// M_BPA.cpp: implementation of the CM_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/M_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CM_BPA::CM_BPA()
{
	m_chType = 'M';
	m_chSubType = ' ';
	m_chChangeCode = ' ';

	m_dTqopp = 0;
	m_dTdopp = 0;
	m_dXqpp = 0;
	m_dXdpp = 0;
	memset(m_strOwner,' ',3);
	m_strOwner[3] = '\0';
	memset(m_strType,' ',2);
	m_strType[2] = '\0';
	memset(m_strNoUnitsThisCard,' ',3);
	m_strNoUnitsThisCard[3] = '\0';
	m_dPF = 0;
	m_dMVA = 0;
	
	m_strCardType[0] = 'M';
}

CM_BPA::CM_BPA(CM_BPA &mBPA):CUnit_BPA(mBPA)
{
	m_dTqopp = mBPA.m_dTqopp;
	m_dTdopp = mBPA.m_dTdopp;
	m_dXqpp = mBPA.m_dXqpp;
	m_dXdpp = mBPA.m_dXdpp;
	strcpy(m_strOwner,mBPA.m_strOwner);
	strcpy(m_strType,mBPA.m_strType);
	strcpy(m_strNoUnitsThisCard,mBPA.m_strNoUnitsThisCard);
	m_dPF = mBPA.m_dPF;
	m_dMVA = mBPA.m_dMVA;
}

CM_BPA::~CM_BPA()
{

}

bool CM_BPA::FillEx(char *buffer)
{
	int i;
	bool bResult = CUnit_BPA::FillEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CM_BPA: FillEx): no basic information!\n");
		return false;
	}
	
	if (strlen(buffer)<17)
	{
		printf("Error in (CM_BPA: FillEx): m has no parameter!\n");
		return false;
	}

	m_dMVA = StrToDouble(&buffer[16],5,1);
	if(EndOfSec(&buffer[16],6))
		return true;
	
	m_dPF = StrToDouble(&buffer[22],3,2);
	if(EndOfSec(&buffer[22],4))
		return true;

	for(i=0;i<3;i++)
	{
		if(!buffer[26+i])
			break;
		else
			m_strNoUnitsThisCard[i] = buffer[26+i];
	}
	m_strNoUnitsThisCard[3] = '\0';
	if(i!=3)
		return true;

	if(EndOfSec(&buffer[29],1))
		return true;

	for(i=0;i<2;i++)
	{
		if(!buffer[30+i])
			break;
		else
			m_strType[i] = buffer[30+i];
	}
	m_strType[2] = '\0';
	if(i!=2)
		return true;

	if(EndOfSec(&buffer[32],1))
		return true;

	for(i=0;i<3;i++)
	{
		if(!buffer[33+i])
			break;
		else
			m_strOwner[i] = buffer[33+i];
	}
	m_strOwner[3] = '\0';
	if(i!=3)
		return true;

	if(EndOfSec(&buffer[36],1))
		return true;
	
	m_dXdpp = StrToDouble(&buffer[37],5,4);
	if(EndOfSec(&buffer[37],5))
		return true;

	m_dXqpp = StrToDouble(&buffer[42],5,4);
	if(EndOfSec(&buffer[42],5))
		return true;

	m_dTdopp = StrToDouble(&buffer[47],4,4);
	if(EndOfSec(&buffer[47],4))
		return true;

	m_dTqopp = StrToDouble(&buffer[51],4,4);

	return true;
}

bool CM_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CM_BPA: UpdateEx): impossible!\n");
		return false;
	}
	
	DoubleToStr(m_dMVA,&buffer[16],5,1);
	buffer[21] = ' ';
	DoubleToStr(m_dPF,&buffer[22],3,2);
	buffer[25] = ' ';
	strcpy(&buffer[26],m_strNoUnitsThisCard);
	buffer[29] = ' ';
	strcpy(&buffer[30],m_strType);
	buffer[32] = ' ';
	strcpy(&buffer[33],m_strOwner);
	buffer[36] = ' ';
	DoubleToStr(m_dXdpp,&buffer[37],5,4);
	DoubleToStr(m_dXqpp,&buffer[42],5,4);
	DoubleToStr(m_dTdopp,&buffer[47],4,4);
	DoubleToStr(m_dTqopp,&buffer[51],4,4);
	
	return true;
}
